﻿using System;
using System.ComponentModel;
using System.Linq.Expressions;

namespace DoVuiKinhThanh
{
    public abstract class GenericViewModelBase<TModelType> : ViewModelBase
       where TModelType : class
    {
        #region IFields

        /// <summary>
        /// The model instance which contains the "real" data of this ViewModel class.
        /// </summary>
        private TModelType m_model;

        #endregion

        #region IMethods        

        protected string GetPropertyName<T>(Expression<Func<T>> propertyExpression)
        {
            return (propertyExpression.Body as MemberExpression).Member.Name;
        }

        #endregion IMethods

        #region IProperties

        /// <summary>
        /// The model instance which contains the "real" data of this ViewModel class.
        /// </summary>
        public TModelType Model
        {
            get
            {
                return m_model;
            }
            set
            {
                if (m_model != value)
                {
                    m_model = value;
                    OnPropertyChanged(() => Model);
                }
            }
        }

        #endregion IProperties
    }
}